/**
 * Adapter for displaying list of specimens
 */

package edu.washington.cs.labspecimentransport.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import edu.washington.cs.labspecimentransport.R;
import edu.washington.cs.labspecimentransport.R.id;
import edu.washington.cs.labspecimentransport.R.layout;
import edu.washington.cs.labspecimentransport.dataobjects.Item;

public class ItemAdapter extends BaseAdapter {
	private Context context;
	private List<Item> items;
	
	public ItemAdapter(Context context, List<Item> items) {
		this.context = context;
		this.items = items;
	}

	public int getCount() {
		return items.size();
	}

	public Item getItem(int pos) {
		return items.get(pos);
	}

	public long getItemId(int pos) {
		return items.indexOf(this.getItem(pos));
	}

	public View getView(int position, View view, ViewGroup parent) {
		Item item = this.getItem(position);
		LinearLayout itemLayout = (LinearLayout) 
			LayoutInflater.from(context).inflate(R.layout.client_single, parent, false);
		
		// display the id of the item
		TextView itemIdField = (TextView) itemLayout.findViewById(R.id.item_id);
		itemIdField.setText("" + item.getId());
		
		return itemLayout;
	}
}
